package com.xkstream.client.presenter;

import com.xkstream.client.api.UserApi;
import com.xkstream.client.api.UserService;
import com.xkstream.client.base.BaseData;
import com.xkstream.client.base.BasePresenter;
import com.xkstream.client.base.BasePresenterImpl;
import com.xkstream.client.rx.RxHelper;
import com.xkstream.client.rx.RxObserver;
import com.xkstream.client.utils.DateUtil;
import com.xkstream.client.utils.LogUtil;

import java.util.Map;

/**
 * Created by xiaoyi on 2017-10-31.
 */

public class AnchorApplyPresenter extends BasePresenterImpl implements AnchorApplyContract.Presenter {
    private AnchorApplyContract.View view;
    private UserService userService;

    public AnchorApplyPresenter(AnchorApplyContract.View view) {
        this.view = view;
        this.userService = UserApi.getInstance().service;
        this.view.setPresenter(this);
    }

    @Override
    public void anchorApply(Map<String, Object> params) {
        view.showLoading();
        LogUtil.e("AnchorApplyPresenter","showLoading " +
                DateUtil.formatTime(System.currentTimeMillis(),"HH:mm:ss:SSS"));
        userService.applyAnchor(params)
                .compose(RxHelper.toUI())
                .subscribe(new RxObserver<BaseData>(this) {
                    @Override
                    protected void onSuccess(BaseData data) {
                        LogUtil.e("AnchorApplyPresenter","hideLoading " +
                                DateUtil.formatTime(System.currentTimeMillis(),"HH:mm:ss:SSS"));
                        view.hideLoading();
                        view.showResult(data);
                    }

                    @Override
                    protected void onFail(String message) {
                        LogUtil.e("AnchorApplyPresenter","hideLoading " +
                                DateUtil.formatTime(System.currentTimeMillis(),"HH:mm:ss:SSS"));
                        view.hideLoading();
                    }
                });
    }
}
